//
//  ReplyViewController.m
//  NewChat
//
//  Created by 马欢 on 16/3/2.
//  Copyright © 2016年 蓝鸥. All rights reserved.
//

#import "ReplyViewController.h"
#import "ReplyTableViewCell.h"
#import "PersonalHomePageTableViewController.h"
#import "TopicTableViewController.h"


@interface ReplyViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *ReplyTV;
@property (weak, nonatomic) IBOutlet UIButton *imageBtn;

@property (weak, nonatomic) IBOutlet UILabel *nickL;
@property (weak, nonatomic) IBOutlet UILabel *timeL;
@property (weak, nonatomic) IBOutlet UILabel *replyL;
@property (weak, nonatomic) IBOutlet UILabel *messageL;
@property (weak, nonatomic) IBOutlet UIButton *voiceBtn;
@property (weak, nonatomic) IBOutlet UIButton *collectBtn;
@property (weak, nonatomic) IBOutlet UIButton *shareBtn;

@property (nonatomic,strong)NSMutableArray *nameArray1;

@property (weak, nonatomic) IBOutlet UIButton *replyBtn;
@end

@implementation ReplyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"主题帖";
    self.edgesForExtendedLayout = UIRectEdgeBottom;
    
    UINib *nib = [UINib nibWithNibName:@"ReplyTableViewCell" bundle:nil];
    [self.ReplyTV registerNib:nib forCellReuseIdentifier:@"ReplyListCell"];
    
    UIBarButtonItem *function = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:(UIBarButtonSystemItemAdd) target:self action:@selector(functionAction)];
    self.navigationItem.rightBarButtonItem = function;
    self.imageBtn.layer.masksToBounds = YES;
    self.imageBtn.layer.cornerRadius = self.imageBtn.frame.size.width/2.0;
    [self.imageBtn addTarget:self action:@selector(lookHer) forControlEvents:(UIControlEventTouchUpInside)];
    [self.imageBtn setBackgroundImage:[UIImage imageNamed:self.imageName] forState:(UIControlStateNormal)];
    self.nickL.text = self.nick;
    self.timeL.text = @"1小时前";
    
    for (int i = 1; i <11; i++) {
        NSString *imageName = [NSString stringWithFormat:@"%d.jpg",i];
        [self.nameArray1 addObject:imageName];
    }
    self.replyL.text = [NSString stringWithFormat:@"%ld回复",self.nameArray1.count];
    self.replyL.textAlignment = NSTextAlignmentCenter;
    self.messageL.text = self.message;
    self.voiceBtn.layer.cornerRadius = 20;
    self.voiceBtn.layer.borderColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1].CGColor;
    self.voiceBtn.layer.borderWidth = 1;
    [self.voiceBtn setTitle:@"                                                  8\"" forState:(UIControlStateNormal)];
    [self.voiceBtn addTarget:self action:@selector(HerVoice) forControlEvents:(UIControlEventTouchUpInside)];
    self.collectBtn.layer.cornerRadius = self.collectBtn.frame.size.width/2.0;
    [self.collectBtn addTarget:self action:@selector(collectHer) forControlEvents:(UIControlEventTouchUpInside)];
    self.shareBtn.layer.cornerRadius = self.shareBtn.frame.size.width/2.0;
    [self.shareBtn addTarget:self action:@selector(shareHer) forControlEvents:(UIControlEventTouchUpInside)];
    
    self.ReplyTV.delegate = self;
    self.ReplyTV.dataSource = self;
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return 10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ReplyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ReplyListCell"];
    
    cell.imageBtn.layer.masksToBounds = YES;
    cell.imageBtn.layer.cornerRadius = cell.imageBtn.frame.size.width/2.0;
    cell.voiceBtn.layer.cornerRadius = 20;
    [cell.voiceBtn setTitle:@"                                        3\"" forState:(UIControlStateNormal)];
    cell.voiceBtn.tag = indexPath.row +201;
    [cell.voiceBtn addTarget:self action:@selector(listenVoice) forControlEvents:(UIControlEventTouchUpInside)];
    
    cell.timeL.text = [NSString stringWithFormat:@"%ld分钟前",indexPath.row+1];
    
    cell.imageBtn.tag = indexPath.row +101;
    [cell.imageBtn addTarget:self action:@selector(toPersonal:) forControlEvents:(UIControlEventTouchUpInside)];
    [cell.imageBtn setBackgroundImage:[UIImage imageNamed:self.nameArray1[indexPath.row]] forState:(UIControlStateNormal)];
    
    cell.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
    cell.voiceBtn.layer.borderColor = [UIColor colorWithRed:250/255.0 green:250/255.0 blue:250/255.0 alpha:1].CGColor;
    cell.voiceBtn.layer.borderWidth = 1;
    return cell;
}

-(void)functionAction{
    NSLog(@"举报");
}
// 修改？？？？
-(void)lookHer{

    
    NSLog(@"让我做个判断");
    
    if ([self.ControlType isEqualToString:@"person"]) {
        NSLog(@"---------------------111");
        [self.navigationController popViewControllerAnimated:YES];
        
    }else if ([self.ControlType isEqualToString:@"topic"]){
        NSLog(@"---------------------222");
        
        PersonalHomePageTableViewController *personalVC = [[PersonalHomePageTableViewController alloc]init];
        personalVC.ControlType = @"push";
        
        [self.navigationController pushViewController:personalVC animated:YES];
        
    }

}
-(void)HerVoice{
    NSLog(@"听她的声音");
}
-(void)collectHer{
    NSLog(@"收藏她");
}
-(void)shareHer{
    NSLog(@"分享她");
}

-(void)toPersonal:(UIButton *)sender{
    PersonalHomePageTableViewController *personalVC = [PersonalHomePageTableViewController new];
//    传值sender.tag
    NSLog(@"查看用户信息,待添加");
    [self.navigationController pushViewController:personalVC animated:YES];
}
-(void)listenVoice{
    NSLog(@"听该用户的回复语音");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSMutableArray *)nameArray1{
    if (!_nameArray1) {
        _nameArray1 = [NSMutableArray array];
    }
    return _nameArray1;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    
}

-(void)viewWillAppear:(BOOL)animated{
    [self.tabBarController.tabBar setHidden:YES];
}
@end
